
<?php

defined('BASEPATH') or die('forbidden');
//登陆异常跟踪
class CrashReport_Controller Extends Controller {
	
	private $dbName;	//数据库名
	
    function _init() {
        check_level(50, segment(0), segment(1));
        require_once(CONFIGPATH . 'inc.php');
        //$this->dbName = "buglist";
        $this->dbName = "crashreport";
    }

    function index() {
        $this->view->display("message/crashreport/index");
    }
    
	function flexigrid() 
	{
		 
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
			
		$sql = "SELECT COUNT(*) AS num FROM ".$this->dbName.".loginreport	 WHERE {$where} ";
		//echo " sql2:$sql ";
		$one = $this->db->one($sql);
		$total = $one['num'];
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
		 
		$sql = "SELECT {$colsinfo} FROM ".$this->dbName.".loginreport  WHERE {$where}  {$orderby} LIMIT {$offset},{$rp}";
		$this->db->query($sql);
		//$id = 0;
		while ($n = $this->db->get_array('default'))
		{			
			$rows[] = array('id' => $n['id'], 'cell' => $n);
		}
		//var_dump($rows);
		$result = array(
	            'page' => $page,
	            'total' => $total,
	            'rows' => $rows
		);
		 
		echo json_encode($result);
	}

    function replay($id = 0)
    {
    	 if ($id === 0)
    	 {
            error(translate('C_INVALID_PARAM_ID', $id));
    	 }        
        if (is_submit()) {
            $rowdata = $_POST['row'];
            
            //echo "<script language='javascript'>this.window.opener = null; window.close();</script> ";
            //print_r($rowdata);
            $value =array('answer'=>$rowdata['answer'],'isanswer'=>'1','replaytime'=>date('Y-m-d h:i:s',time()));            
            $result = $this->buglist_db->update('player_buglist', $value, array('id' => $id));
            cp_tips($result > 0 ? "success" : "error");
            //echo "<script language='javascript'>this.window.opener = null; window.close();</script> ";
            //echo "<script language='javascript'>self.opener=null;self.close();</script>";
           	// return;
           	//echo "<script language='javascript'>window.parent.$.dialog.close('replay');</script> ";
           	echo "<script language='javascript'>window.close();</script> ";
        }
        $row = $this->buglist_db->one("SELECT * FROM ".$this->dbName.".loginreport WHERE id={$id} ");
        $this->view->assign("row", $row);
    	$this->view->display("message/crashreport/replay");
    }
    
	function del($id = 0)
    {    	
     	if ($id === 0)
    	 {
            error(translate('C_INVALID_PARAM_ID', $id));
    	 }         
        
		$c = 0;
        $r = '';
 
        if ($this->db->delete($this->dbName.'.loginreport',array('id' => $id))) {
            $c = 1;
            $r = translate('C_TIPS_SUCCESS_TEXT');
        } else {
            $r = translate('C_TIPS_ERROR_TEXT');
        }
        json_output($c, $r);
    }
    
    

}